#ifndef SMSG_H_
#define SMSG_H_
/*********************************************************/
#include "Poco/Runnable.h"
#include <Poco/DOM/Document.h>
#include <Poco/DOM/NodeIterator.h>
#include <Poco/Net/SocketAddress.h>

#include <string>
/*********************************************************/
class sMsg : public Poco::Runnable
{
private:
	// Methods
	void run() { execute(); }
	virtual void deserialize(Poco::XML::NodeIterator&) = 0;	// Deserializes a job

protected:
	// Members
	mutable unsigned long 		id;			// The job id ( used for unique identification together with the sender ip/port)
	Poco::Net::SocketAddress	addr;			// The address from which the job was issued

	// Methods
	void ack() const;					// Send an acknowledgement for this message

public:
	// Methods
	void setSenderAddr(const Poco::Net::SocketAddress&);	// Set the sender address in the job
	Poco::Net::SocketAddress getSenderAddr() const;		// Returns the address from which the job came from
	void setID(const unsigned long id);			// Set the job id
	unsigned long getID() const;				// Returns the job id
	sMsg* getAck() const;					// Returns an ack packet for this message

	static sMsg* deserialize(const std::string&);		// Create a job from an xml string
	virtual std::string serialize() const = 0;		// Serialize the job to an xml string
	virtual void execute() = 0; 				// Execute the job

	// Construction & Destruction
	sMsg() {};
	virtual ~sMsg() {};
};
/*********************************************************/
#endif //SMSG_H_
